﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System.Runtime.Serialization;
using System;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Reflection;
#if USE_HYPER
using Hyper.ComponentModel;
#endif

namespace BrainTechLLC.ThreadSafeObjects
{
#if NO_SILVERLIGHT
[TypeDescriptionProvider(typeof(HyperTypeDescriptionProvider))]
#endif
    [Serializable]
    [DataContract]
    public class CacheBase
    {
        [NonSerialized, XmlIgnore]
        protected Lockable _repopLock;

        [NonSerialized, XmlIgnore]
        protected bool _dirty;

        [NonSerialized, XmlIgnore]
        protected object _defaultPopulateParam;

        [NonSerialized, XmlIgnore]
        protected object[] _storedArgs;

        /// <summary>
        /// True if the cache object has been marked as dirty, otherwise false
        /// </summary>
        public bool Dirty { get { return _dirty; } set { _dirty = value; } }

        /// <summary>
        /// The default parameter to pass in the cache population function
        /// </summary>
        public object DefaultPopulateParam { get { return _defaultPopulateParam; } set { _defaultPopulateParam = value; } }

        /// <summary>
        /// Storage for other arguments passed into the cache population function
        /// </summary>
        public object[] StoredArgs { get { return _storedArgs; } set { _storedArgs = value; } }

        /// <summary>
        /// Marks the cache as dirty
        /// </summary>
        public virtual void MarkDirty() { _dirty = true; }

        private MethodInfo PopulateCacheMethodInfo { get; set; }
    }
}
